package com.yuncheng.spcyApi.spcy;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.yuncheng.constant.SysUserConstant;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.vo.CurrentUserVo;
import com.yuncheng.vo.HttpResult;
import org.apache.commons.collections.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.alog.utils.StringEmptyUtils;
import com.yuncheng.spcyApi.bo.ParamsBo;
import com.yuncheng.spcyApi.constant.*;
import com.yuncheng.spcyApi.constant.common.LogConstant;
import com.yuncheng.spcyApi.constant.common.SpcyCommonConstant;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.exception.BusinessException;
import com.yuncheng.spcyApi.flow.JcyNdkpFlowService;
import com.yuncheng.spcyApi.flow.SpcyFlowConstant;
import com.yuncheng.spcyApi.mapper.SpcyRsHcyMapper;
import com.yuncheng.spcyApi.service.ISpcyKpNdkpBasicService;
import com.yuncheng.spcyApi.service.ISpcyKpNdkpjhService;
import com.yuncheng.spcyApi.service.ISpcyKpNdpxjlService;
import com.yuncheng.spcyApi.service.IYcSysUserService;
import com.yuncheng.spcyApi.spcyService.ZdyUploadFileService;
import com.yuncheng.spcyApi.utils.*;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.jcy.RsHcyVo;
import com.yuncheng.spcyApi.vo.ndkp.NdkpFlowMapVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import utils.DateConversionUtils;
import utils.ExcelUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;

/**
 * @author hua
 */
@Api(tags = "检查员-年度考评计划接口")
@RestController
@RequestMapping("/api/spzx-spcy/ndkpjh")
public class JcyNdkpJhController {

    @Resource
    @Lazy
    private ISpcyKpNdkpjhService spcyKpNdkpjhService;

    @Resource
    @Lazy
    private ISpcyKpNdkpBasicService spcyKpNdkpBasicService;

    @Resource
    @Lazy
    private ISpcyKpNdpxjlService spcyKpNdpxjlService;

    @Resource
    @Lazy
    private SpcyRsHcyMapper spcyRsHcyMapper;

    @Resource
    @Lazy
    private JcyNdkpFlowService jcyNdkpFlowService;

    @Resource
    @Lazy
    private IYcSysUserService sysUserService;

    @Resource
    private ZdyUploadFileService zdyUploadFileService;


    @Log(title = "年度计划-分页查询")
    @ApiOperation(value = "年度计划-分页查询")
    @GetMapping(value = "ndjhPageList")
    public HttpResult ndjhPageList(SpcyKpNdkpjh bean, String gjz, PageVo pageVo){
        Page<SpcyKpNdkpjh> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcyKpNdkpjh> queryWrapper = new LambdaQueryWrapper<>();

        if (StringUtils.isNotBlank(gjz)){
            queryWrapper
                    .and(f->f.like(SpcyKpNdkpjh::getFkpnd, gjz)
                            .or()
                            .like(SpcyKpNdkpjh::getFstate, gjz)
                            .or()
                            .like(SpcyKpNdkpjh::getFkpmc, gjz)
                            .or()
                            .like(SpcyKpNdkpjh::getFbz, gjz)
                    );
        }

        queryWrapper.orderByDesc(SpcyKpNdkpjh::getCreateTime);
        Page<SpcyKpNdkpjh> pageList = spcyKpNdkpjhService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    @Log(title = "年度计划-相关人员-分页查询")
    @ApiOperation(value = "年度计划-相关人员-分页查询")
    @GetMapping(value = "ndjhRyPageList")
    public HttpResult ndjhRyPageList(SpcyKpNdkpBasic query, String id, String gjz, PageVo pageVo){
        if (StringUtils.isBlank(id)){
            id = "0";
        }
        Page<SpcyKpNdkpBasic> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcyKpNdkpBasic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SpcyKpNdkpBasic::getFkpjhid, id);

        queryWrapper.like(StringUtils.isNotBlank(query.getFgzdw()), SpcyKpNdkpBasic::getFgzdw, query.getFgzdw());
        queryWrapper.like(StringUtils.isNotBlank(query.getFusermc()), SpcyKpNdkpBasic::getFusermc, query.getFusermc());
        queryWrapper.like(StringUtils.isNotBlank(query.getFyear()), SpcyKpNdkpBasic::getFyear, query.getFyear());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFndzhkpjg()), SpcyKpNdkpBasic::getFndzhkpjg, query.getFndzhkpjg());
        queryWrapper.eq(StringUtils.isNotBlank(query.getFsftjkh()), SpcyKpNdkpBasic::getFsftjkh, query.getFsftjkh());

        queryWrapper.ge(query.getFsjjccs() != null, SpcyKpNdkpBasic::getFsjjccs, query.getFsjjccs());

        if (StringUtils.isNotBlank(gjz)){
            queryWrapper
                    .and(f->f.like(SpcyKpNdkpBasic::getFyear, gjz)
                            .or()
                            .like(SpcyKpNdkpBasic::getFusermc, gjz)
                            .or()
                            .like(SpcyKpNdkpBasic::getFgzdw, gjz)
                    );
        }

        queryWrapper.orderByDesc(SpcyKpNdkpBasic::getFsjjccs);
        queryWrapper.orderByDesc(SpcyKpNdkpBasic::getCreateTime);
        Page<SpcyKpNdkpBasic> pageList = spcyKpNdkpBasicService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    @Log(title = "年度考核管理人员-分页查询")
    @ApiOperation(value = "年度考核管理人员-分页查询")
    @GetMapping(value = "queryNdkpglRyPageList")
    public HttpResult queryNdkpglRyPageList(SpcyKpNdkpBasic query, String gjz, PageVo pageVo){
        Page<SpcyKpNdkpBasic> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());

        LambdaQueryWrapper<SpcyKpNdkpBasic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(query.getFgzdw()), SpcyKpNdkpBasic::getFgzdw, query.getFgzdw());
        queryWrapper.like(StringUtils.isNotBlank(query.getFusermc()), SpcyKpNdkpBasic::getFusermc, query.getFusermc());
        queryWrapper.like(StringUtils.isNotBlank(query.getFyear()), SpcyKpNdkpBasic::getFyear, query.getFyear());
        queryWrapper.like(StringUtils.isNotBlank(query.getFndzhkpjg()), SpcyKpNdkpBasic::getFndzhkpjg, query.getFndzhkpjg());

        queryWrapper.ge(query.getFsjjccs() != null, SpcyKpNdkpBasic::getFsjjccs, query.getFsjjccs());

        if (StringUtils.isNotBlank(gjz)){
            queryWrapper
                    .and(f->f.like(SpcyKpNdkpBasic::getFyear, gjz)
                            .or()
                            .like(SpcyKpNdkpBasic::getFusermc, gjz)
                            .or()
                            .like(SpcyKpNdkpBasic::getFgzdw, gjz)
                    );
        }
        queryWrapper.eq(SpcyKpNdkpBasic::getFsftjkh, SpcyConstant.NDKP_SFTJKP_YES);

        queryWrapper.orderByDesc(SpcyKpNdkpBasic::getFsjjccs);
        queryWrapper.orderByDesc(SpcyKpNdkpBasic::getFndkpsj);
        Page<SpcyKpNdkpBasic> pageList = spcyKpNdkpBasicService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }

    @Log(title = "年度计划-新增/保存")
    @ApiOperation(value = "年度计划-新增/保存")
    @PostMapping(value = "ndjhSave")
    public HttpResult ndjhSave(@RequestBody SpcyKpNdkpjh bean) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {

        if (StringEmptyUtils.isBlank(bean.getId())){

            bean = spcyKpNdkpjhService.addNdjh(bean);
        }else {

            spcyKpNdkpjhService.updateNdjh(bean);
        }

        return HttpResultVo.HttpResultSave(bean, "保存成功");

    }

    @Log(title = "年度计划-提交")
    @ApiOperation(value = "年度计划-提交")
    @GetMapping(value = "submitNdjh")
    public HttpResult submitNdjh(@RequestParam(value = "id",defaultValue = "")String fkpjhid){
        if (StringUtils.isBlank(fkpjhid)){
            return HttpResult.error("参数为空！");
        }

        SpcyKpNdkpjh bean = spcyKpNdkpjhService.getById(fkpjhid);
        if (bean == null){
            return HttpResult.error("没有相匹配的数据！");
        }

        List<SpcyKpNdkpBasic> ryList = spcyKpNdkpBasicService.list(new LambdaQueryWrapper<SpcyKpNdkpBasic>()
                .eq(SpcyKpNdkpBasic::getFkpjhid, fkpjhid));
        if (CollectionUtil.isEmpty(ryList)){
            return HttpResult.error("请生成考评人员！");
        }

        bean.setFstate("已开始");
        spcyKpNdkpjhService.updateById(bean);

        initNdRyJob(fkpjhid); // 生成流程

        return HttpResult.ok("提交成功");
    }

    @Log(title = "年度计划-删除")
    @ApiOperation(value = "年度计划-删除")
    @DeleteMapping(value = "deleteNdjh")
    public HttpResult deleteNdjh(@RequestParam(value = "id",defaultValue = "")String fkpjhid){

        if (StringUtils.isBlank(fkpjhid)){
            throw new BusinessException("参数为空！");
        }

        spcyKpNdkpjhService.deleteNdjh(fkpjhid);
        spcyKpNdkpBasicService.remove(new LambdaQueryWrapper<SpcyKpNdkpBasic>()
                .eq(SpcyKpNdkpBasic::getFkpjhid, fkpjhid));
        zdyUploadFileService.deleteFileByBatch(fkpjhid);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "年度计划人员-删除")
    @ApiOperation(value = "年度计划人员-删除")
    @DeleteMapping(value = "deleteNpjhRy")
    public HttpResult deleteNpjhRy(@RequestParam(value = "ids",defaultValue = "")String ids){

        if (StringUtils.isBlank(ids)){
            throw new BusinessException("参数为空！");
        }

        spcyKpNdkpBasicService.remove(new LambdaQueryWrapper<SpcyKpNdkpBasic>()
                .in(SpcyKpNdkpBasic::getId, StringPatternUtils.getListByIds(ids)));

        return HttpResult.ok("删除成功");
    }


    @Log(title = "年度计划-附件上传")
    @ApiOperation(value = "年度计划-附件上传")
    @PostMapping(value = "uploadFile")
    public HttpResult<?> uploadFile(@RequestParam("file") MultipartFile[] file,
                                        @RequestParam(value = "id",defaultValue = "")String fkpjhid){
        if (StringEmptyUtils.isBlank(fkpjhid)){
            throw new BusinessException("参数为空！");
        }
        SpcyKpNdkpjh bean = spcyKpNdkpjhService.getById(fkpjhid);
        if (bean == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        zdyUploadFileService.deleteFileByBatch(fkpjhid);

        String wjid = GetUuIdUtils.ReplaceUuId();
        zdyUploadFileService.uploadFile(file, fkpjhid, LogConstant.LOGS_JCY_NDKPJH, SpcyConstant.JCY_NDKP_JH_FILE_BASE_URL+"/"+ DateConversionUtils.DateToYear(new Date()), wjid);

        String wjHttpUrl = zdyUploadFileService.genWjllHttpUrl(wjid);
        bean.setFfwfjdz(wjHttpUrl);
        spcyKpNdkpjhService.updateById(bean);

        return HttpResultVo.HttpResultSave(bean,"上传成功");
    }

//    @Log(title = "获取手动添加人员-分页查询")
//    @ApiOperation(value = "获取手动添加人员-分页查询")
    @GetMapping(value = "getSdtjryPageList")
    public HttpResult getSdtjryPageList(RsHcyVo query, String gjz, PageVo pageVo){
        Page<RsHcyVo> page = new Page<>(pageVo.getPageNo(), pageVo.getPageSize());
        query.setFstate(SpcyCommonConstant.JCY_STATE_YX);
        query.setStatus(SysUserConstant.STATUS_YES);

        Page<RsHcyVo> pageList = spcyRsHcyMapper.pageJcyAccountList(page, query, SpcyConstant.HCY_USERTYPE_JCY, gjz);
        return HttpResult.ok(pageList);
    }

//    @Log(title = "手动添加人员")
//    @ApiOperation(value = "手动添加人员")
    @PostMapping(value = "sdtjNdkpRy")
    public HttpResult sdtjNdkpRy(@RequestBody ParamsBo paramsBo){
        if (StringUtils.isBlank(paramsBo.getId())){
            throw new BusinessException("参数为空！");
        }
        if (StringUtils.isBlank(paramsBo.getIds())){
            throw new BusinessException("请选择人员为空！");
        }

        SpcyKpNdkpjh bean = spcyKpNdkpjhService.getById(paramsBo.getId());
        if (bean == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        String fyear = StringUtils.isNotBlank(bean.getFkpnd()) ? bean.getFkpnd() : DateConversionUtils.DateToYear(new Date());

        List<String> userIdList = StringPatternUtils.getListByIds(paramsBo.getIds());

        List<YcSysUser> userList = sysUserService.listByIds(userIdList);
        if (CollectionUtil.isNotEmpty(userList)){
            for (YcSysUser user : userList) {
                this.initNdkpRyxx(bean.getId(), user.getId(), user.getRealname(), user.getFgzdw(), fyear);
            }
        }

        return HttpResult.ok("添加成功");
    }

    @Log(title = "保存考评人员年度培训记录")
    @ApiOperation(value = "保存考评人员年度培训记录")
    @PostMapping(value = "saveNpryNdPxjl")
    public HttpResult saveNpryNdPxjl(@RequestBody ParamsBo paramsBo) throws InvocationTargetException, IllegalAccessException {
        jcyNdkpFlowService.saveNpryNdPxjl(paramsBo);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "验证年度培训时长(true: 大于60小时)")
    @ApiOperation(value = "验证年度培训时长(true: 大于60小时)")
    @GetMapping(value = "verifyNdpxsc")
    public HttpResult verifyNdpxsc(@RequestParam(value = "id",defaultValue = "") String fndkpid){
        String pxsc = spcyKpNdpxjlService.getTotalLearningHoursTheCurrentYearByNdkpId(fndkpid);
        int flag = new BigDecimal(pxsc).compareTo(new BigDecimal("60"));
        if (flag > 0 || flag == 0){
            return HttpResult.ok(true);
        }else {
            return HttpResult.ok(false);
        }
    }

    @Log(title = "获取年度培训记录列表")
    @ApiOperation(value = "获取年度培训记录列表")
    @GetMapping(value = "queryNdpxjlByNdkpId")
    public HttpResult queryNdpxjlByNdkpId(@RequestParam(value = "id",defaultValue = "") String fndkpid) {
        List<SpcyKpNdpxjl> list = spcyKpNdpxjlService.getNdpxjlByNdkpId(fndkpid);

        return HttpResult.ok(list);
    }

    @Log(title = "删除年度培训记录-根据记录id")
    @ApiOperation(value = "删除年度培训记录-根据记录id")
    @GetMapping(value = "deleteNdpxjl")
    public HttpResult deleteNdpxjl(@RequestParam(value = "id",defaultValue = "") String id) {
        spcyKpNdpxjlService.deleteNdpxjlById(id);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "批量获取选择的人员列表")
    @ApiOperation(value = "批量获取选择的人员列表")
    @PostMapping(value = "batchGetSelectRyList")
    public HttpResult batchGetSelectRyList(@RequestBody NdkpFlowMapVo flowMapVo){
        if (StringUtils.isBlank(flowMapVo.getIds())){
            return HttpResult.ok();
        }

        List<SpcyKpNdkpBasic> list = spcyKpNdkpBasicService.listByIds(StringPatternUtils.getListByIds(flowMapVo.getIds()));

        return HttpResult.ok(list);
    }

    @Log(title = "批量提交并设置考核结果")
    @ApiOperation(value = "批量提交并设置考核结果")
    @PostMapping(value = "batchSubmitNdkp")
    public HttpResult batchSubmitNdkp(@RequestBody NdkpFlowMapVo flowMapVo){
        jcyNdkpFlowService.batchSubmitNdkp(flowMapVo);

        return HttpResult.ok("提交成功");
    }

    @Log(title = "导出年度考评基本信息数据-表格excel")
    @ApiOperation(value = "导出年度考评基本信息数据-表格excel")
    @GetMapping("/exportNdkpData")
    public void exportNdkpData(@RequestParam(value = "ids",defaultValue = "")String ids,
                                 SpcyKpNdkpBasic query,
                                 @RequestParam(value = "gjz",defaultValue = "") String gjz,
                                 @RequestParam(value = "id",defaultValue = "") String fkpjhid,
                                 OrderItemVo orderItemVo,
                                 HttpServletResponse response){

        List<String> IdsList = StringPatternUtils.getListByIds(ids);

        List<SpcyKpNdkpBasic> resultDataList = new ArrayList<>(); // 导出的数据

        // 多选导出
        if (StringUtils.isNotEmpty(ids)) {
            resultDataList = spcyKpNdkpBasicService.listByIds(IdsList);

        }else {
            LambdaQueryWrapper<SpcyKpNdkpBasic> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(StringUtils.isNotBlank(fkpjhid), SpcyKpNdkpBasic::getFkpjhid, fkpjhid);
            queryWrapper.like(StringUtils.isNotBlank(query.getFgzdw()), SpcyKpNdkpBasic::getFgzdw, query.getFgzdw());
            queryWrapper.like(StringUtils.isNotBlank(query.getFusermc()), SpcyKpNdkpBasic::getFusermc, query.getFusermc());
            queryWrapper.like(StringUtils.isNotBlank(query.getFyear()), SpcyKpNdkpBasic::getFyear, query.getFyear());
            queryWrapper.eq(StringUtils.isNotBlank(query.getFndzhkpjg()), SpcyKpNdkpBasic::getFndzhkpjg, query.getFndzhkpjg());
            queryWrapper.eq(StringUtils.isNotBlank(query.getFsftjkh()), SpcyKpNdkpBasic::getFsftjkh, query.getFsftjkh());

            queryWrapper.ge(query.getFsjjccs() != null, SpcyKpNdkpBasic::getFsjjccs, query.getFsjjccs());

            if (StringUtils.isNotBlank(gjz)){
                queryWrapper
                        .and(f->f.like(SpcyKpNdkpBasic::getFyear, gjz)
                                .or()
                                .like(SpcyKpNdkpBasic::getFusermc, gjz)
                                .or()
                                .like(SpcyKpNdkpBasic::getFgzdw, gjz)
                        );
            }

            if (StringUtils.isNotBlank(orderItemVo.getOrderItem())){
                OrderItemUtils.setOrderItem(queryWrapper, orderItemVo);
            }else {
                queryWrapper.orderByDesc(SpcyKpNdkpBasic::getFsjjccs);
                queryWrapper.orderByDesc(SpcyKpNdkpBasic::getFndkpsj);
            }

            resultDataList = spcyKpNdkpBasicService.list(queryWrapper);
        }

        String[] titles = new String[]{"序号","姓名","工作单位","年度","参加检查次数","出勤率",
                "日常考核优秀率","日常考核合格率","日常考核不合格率","总结报送是否提交","提交时间","年度考核结果"};
        List<List<String>> resultList = new ArrayList<>();

        resultList.add(CollectionUtil.newArrayList(titles));
        List<String> dataList = null;

        for (int order = 0; order < resultDataList.size(); order++){
            dataList = new ArrayList<>();

            dataList.add(String.valueOf(order+1));

            dataList.add(resultDataList.get(order).getFusermc());
            dataList.add(resultDataList.get(order).getFgzdw());
            dataList.add(resultDataList.get(order).getFyear());

            dataList.add(String.valueOf(Optional.ofNullable(resultDataList.get(order).getFsjjccs()).orElseGet(()->0)));
            dataList.add(resultDataList.get(order).getFcql());

            dataList.add(resultDataList.get(order).getFrckhyxl());
            dataList.add(resultDataList.get(order).getFrckhhgl());
            dataList.add(resultDataList.get(order).getFrckhbhgl());

            dataList.add(resultDataList.get(order).getFsftjkh());
            if (resultDataList.get(order).getFndkpsj() != null) {
                dataList.add(DateConversionUtils.DateToDays(resultDataList.get(order).getFndkpsj()));
            }else {
                dataList.add("");
            }

            dataList.add(Optional.ofNullable(resultDataList.get(order).getFndzhkpjg()).orElseGet(()->""));

            resultList.add(dataList);
        }

        // 文件名称
        String title = "考核信息";
        ExcelUtils.getLocalTitleExcel(resultList,title,response);
    }

    @Log(title = "年度计划人员-生成人员")
    @ApiOperation(value = "年度计划人员-生成人员")
    @GetMapping(value = "initNpjhRy")
    public HttpResult initNpjhRy(@RequestParam(value = "id",defaultValue = "") String fkpjhid){
        if (StringUtils.isBlank(fkpjhid)){
            throw new BusinessException("参数为空！");
        }
        SpcyKpNdkpjh bean = spcyKpNdkpjhService.getById(fkpjhid);
        if (bean == null){
            throw new BusinessException("没有相匹配的数据！");
        }

        String fyear = StringUtils.isNotBlank(bean.getFkpnd()) ? bean.getFkpnd() : DateConversionUtils.DateToYear(new Date());

        RsHcyVo rsHcyVo = new RsHcyVo();
        rsHcyVo.setStatus(SysUserConstant.STATUS_YES);
        rsHcyVo.setFstate(SpcyCommonConstant.JCY_STATE_YX);
        rsHcyVo.setFusertype(SpcyConstant.HCY_USERTYPE_JCY);
        List<RsHcyVo> hcyList = spcyRsHcyMapper.getRsHcyList(rsHcyVo);

        List<String> userIdList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(hcyList)){
            for (RsHcyVo hcyVo : hcyList){

                if (userIdList.contains(hcyVo.getFuserid())){
                    continue;
                }
                userIdList.add(hcyVo.getFuserid());

                this.initNdkpRyxx(bean.getId(), hcyVo.getFuserid(), hcyVo.getRealname(), hcyVo.getFgzdw(), fyear);
            }
        }

        return HttpResult.ok("生成成功");
    }

    // 初始化年度考评人员信息
    private void initNdkpRyxx(String fkpjhid, String fuserid, String realname, String fgzdw, String fyear){
        SpcyKpNdkpBasic ndkp = new SpcyKpNdkpBasic();
        ndkp.setId(GetUuIdUtils.ReplaceUuId());
        ndkp.setFuserid(fuserid);
        ndkp.setFusermc(realname);
        ndkp.setFgzdw(fgzdw);
        ndkp.setFyear(fyear);
        ndkp.setFsfcykp(SpcyConstant.NDKP_SFCYKP_YES);
        String zjkssj = fyear+"-01-01";
        String zjjssj = fyear+"-12-31";
        ndkp.setFzjkssj(DateUtil.parse(zjkssj));
        ndkp.setFzjjssj(DateUtil.parse(zjjssj));
        ndkp.setFlczt(SpcyFlowConstant.LCZT_LCZB);

        List<SpcyKpNdkpBasic> ndkpList = spcyKpNdkpBasicService.list(new LambdaQueryWrapper<SpcyKpNdkpBasic>()
                .eq(SpcyKpNdkpBasic::getFuserid, fuserid)
                .eq(SpcyKpNdkpBasic::getFyear, fyear));
        if (CollectionUtils.isEmpty(ndkpList)) {
            ndkp.setFkpjhid(fkpjhid);
            spcyKpNdkpBasicService.save(ndkp);
            jcyNdkpFlowService.jsJoinKpxx(ndkp.getId()); // 计算年度统计数据
        }
    }

    // 初始化年度考评人员流程
    private void initNdRyJob(String fkpjhid){

        List<SpcyKpNdkpBasic> ryList = spcyKpNdkpBasicService.list(new LambdaQueryWrapper<SpcyKpNdkpBasic>()
                .eq(SpcyKpNdkpBasic::getFkpjhid, fkpjhid));
        if (CollectionUtil.isNotEmpty(ryList)){
            CurrentUserVo currentUser = GetCurrentUserUtils.getCurrentUser();
            for (int i = 0; i < ryList.size(); i++){
                jcyNdkpFlowService.initJob(ryList.get(i).getId(), currentUser); // 初始化流程
            }
        }
    }



}
